#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() 
{
    int N, V;
    cin >> N >> V;
    vector<int> v(N + 1);
    vector<int> w(N + 1);
    vector<int> f(V + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> v[i] >> w[i];
    }
    
    for (int i = 1; i <= N; ++i) {
        for (int j = V; j >= v[i]; --j) {
            f[j] = max(f[j], f[j - v[i]] + w[i]);
        }
    }
    

    cout << f[V] << endl;
    return 0;
}